// (function () {
// "use strict";

const blackList = ["rm-list"];

const removeEl = (el: HTMLElement) => {
    try {
        if (el.parentNode) {
            el.parentNode.removeChild(el);
        }
    } catch (error) {
        console.warn(error);
    }
};

const delStopImg = () => {
    const iframeEl = document.querySelector("iframe");
    // console.log(" window === ", window);
    if (iframeEl && iframeEl.contentDocument) {
        const closeEl = iframeEl.contentDocument.querySelector("#player_pic");
        removeEl(closeEl as HTMLElement);
    }
};
window.addEventListener("load", () => {
    delStopImg();
});
//
const checkHasString = ({ str, listFlag }) => {
    for (let index = 0; index < listFlag.length; index++) {
        const flag = listFlag[index];
        if (str.indexOf(flag) >= 0) {
            return true;
        }
    }
    return false;
};
const handleChildren = (addedNodes) => {
    if (addedNodes.length > 0) {
        // eslint-disable-next-line no-loop-func
        const flag = addedNodes.length - 1;
        for (let index = flag; index >= 0; index -= 1) {
            const element = addedNodes[index];
            if (
                element.className &&
                element.className.length > 1 &&
                checkHasString({
                    str: element.className,
                    listFlag: blackList,
                })
            ) {
                removeEl(element);
            } else {
                const subChildren = element.childNodes;
                handleChildren(subChildren);
            }
        }
    }
};
/ ads /;
const handleAds = () => {
    blackList.forEach((blackItem) => {
        const nodes = document.querySelectorAll(`.${blackItem}`);
        if (nodes.length > 1) {
            const flag = nodes.length - 1;
            for (let index = flag; index >= 0; index -= 1) {
                const element = nodes[index];
                removeEl(element as HTMLElement);
            }
        }
    });
};

const handleObserv = () => {
    if (window.__myobserver__) {
        const config = {
            attributes: false,
            childList: true,
            subtree: true,
        };
        // 当观察到变动时执行的回调函数
        const callback = function (mutationsList) {
            for (const mutation of mutationsList) {
                if (mutation.type === "childList") {
                    const addedNodes = mutation.addedNodes;
                    handleChildren(addedNodes);
                }
            }
        };
        // 创建一个观察器实例并传入回调函数
        window.__myobserver__ = new MutationObserver(callback);
        // 以上述配置开始观察目标节点
        window.__myobserver__.observe(document, config);
    }
};
const delObserv = () => {
    if (window.__myobserver__) {
        window.__myobserver__.disconnect();
        window.__myobserver__ = null;
    }
};
// init

const initLogic = () => {
    delStopImg();
    handleAds();
    handleObserv();
};
initLogic();
setTimeout(() => {
    initLogic();
}, 1500);
// call time strategy
window.addEventListener("pageshow", () => {
    initLogic();
});
window.addEventListener("pagehide", () => {
    initLogic();
});
document.addEventListener("visibilitychange", () => {
    initLogic();
});
window.addEventListener("unload", () => {
    delObserv();
});
//
// })();
